package aop02;

import java.lang.reflect.Proxy;

/**
 * @author 石小俊
 */
public class Test {

    public static void main(String[] args) {
        // loader：定义代理的类的类加载器。此处即为:实现类的类加载器
        // interfaces：代理的类要实现的接口列表。此处即为:实现类要实现的接口列表
        // h：指派方法调用的调用处理程序。即:交叉业务逻辑的处理代码
        // newProxyInstance(ClassLoader loader,Class<?>[] interfaces,InvocationHandler h)
        SomeService someService = (SomeService) Proxy.newProxyInstance(SomeServiceImpl.class.getClassLoader(),
                SomeServiceImpl.class.getInterfaces(),
                new LogInvocationHandler(new SomeServiceImpl()));

        someService.doSome();
        System.out.println("************************************");
        someService.doOther();
        System.out.println("************************************");
        someService.login("admin","123456");
        System.out.println("************************************");
        someService.login("aaa","123");
        System.out.println("************************************");

        OtherService otherService = (OtherService) Proxy.newProxyInstance(OtherServiceImpl.class.getClassLoader(),
                OtherServiceImpl.class.getInterfaces(),
                new LogInvocationHandler(new OtherServiceImpl()));
        otherService.doSome();
        System.out.println("************************************");
        otherService.doOther();
    }

}
